<?php
header("content-type:text/html;charset=utf-8");
include_once ("./PHPExcel-1.8/Classes/PHPExcel.php");
//实例化一个表格
$excel=PHPExcel_IOFactory::load("exam.xls");
//print_r($excel);
//确定一个表格
$sheet=$excel->getActiveSheet();
//获取最大行
$rows=$sheet->getHighestRow();
//print_r($rows);
//获取最大列
$col=$sheet->getHighestColumn();
//print_r($col);
//循环输入数据
for ($i=2;$i<=$rows;$i++)
{
    for ($j="A";$j<=$col;$j++)
    {
        $data[$i-2][]=$sheet->getCell($j.$i)->getValue();
    }
}
//print_r($data);die;
//实例化pdo
$db=new PDO("mysql:host=127.0.0.1;dbname=myexam;charset=utf8",'root','root');
foreach($data as $key=>$val)
{
    $name=$val[0];
    $age=$val[1];
    $xb=$val[2];
    $sql="insert into exam value(null,'$name','$age','$xb')";
//    print_r($sql);
    $res=$db->exec($sql);
}
echo $res;





















